using System;
using System.Collections.Generic;
using System.Text;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.Common.Configuration;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.JiraIntegrationService;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.View.Domain;

namespace Bosphorus.Integration.Jira.Thor.Client.PlugIn.Core.Forms
{
    public class IssueController
    {
        public IList<IssueViewModel> GetIssueViewModelByProject(string projectKey)
        {
            JiraIntegrationService.JiraIntegrationService jiraIntegrationService = new JiraIntegrationService.JiraIntegrationService();
            jiraIntegrationService.Url = ConfigurationManager.WebServiceUrl;
            IssueView[] issueViews = jiraIntegrationService.GetIssuesByProject(projectKey);
            return ConvertToIssueViewModelList(issueViews);
        }

        private IList<IssueViewModel> ConvertToIssueViewModelList(IssueView[] issueViews)
        {
            IList<IssueViewModel> issueViewModels = new List<IssueViewModel>();
            foreach (IssueView issueView in issueViews)
            {
                IssueViewModel issueViewModel = new IssueViewModel(issueView);
                issueViewModels.Add(issueViewModel);
            }

            return issueViewModels;
        }
    }
}
